package cn.com.recode.d对象属性操作最好在对象类内部;

public class Movie {

    public static final int CHILDRENS = 2;

    public static final int REGULAR = 0;

    public static final int NEW_RELEASE = 1;

    private String _title;

    private int _priceCode;

    public Movie(String title, int priceCode) {
        this._title = title;
        this._priceCode = priceCode;
    }

    public String getTitle() {
        return _title;
    }

    public void setTitle(String title) {
        this._title = title;
    }

    public int getPriceCode() {
        return _priceCode;
    }

    public void setPriceCode(int priceCode) {
        this._priceCode = priceCode;
    }


    /**
     * 最好不要在另一个对象的属性基础上运用switch语句,如果不得不使用，也应该放在对象自己的数据上使用
     * @param daysRented
     * @return
     */
    public double getCharge(int daysRented) {
        double thisAmout = 0;
        switch (getPriceCode()) {
            case REGULAR:
                thisAmout += 2;
                if (daysRented > 2) {
                    thisAmout += (daysRented - 2) * 1.5;
                }
                break;
            case Movie.NEW_RELEASE:
                thisAmout += daysRented * 3;
                break;
            case Movie.CHILDRENS:
                thisAmout += 1.5;
                if (daysRented > 3) {
                    thisAmout += (daysRented - 3) * 1.5;
                }
                break;
        }
        return thisAmout;
    }

    /**
     * 对于对象属性的操作,最好放在对象内部
     * @param daysRented
     * @return
     */
    public int getFrenquentRenterPoints(int daysRented) {
        int frenquentRenterPoints = 0;
        if ((getPriceCode() == Movie.NEW_RELEASE) && daysRented > 1) {
            frenquentRenterPoints = 2;
        }else{
            frenquentRenterPoints = 1;
        }
        return frenquentRenterPoints;
    }
}
